package nl.saxion.security.gui;

import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;

import nl.saxion.security.config.Config;

import nl.saxion.security.gui.elements.AbstractPassPanel;
import nl.saxion.security.gui.elements.AbstractSyncListPanel;

import nl.saxion.security.gui.elements.AbstractPathPanel;

import com.google.inject.Inject;
import com.google.inject.name.Named;

public class MainPanel extends JPanel implements GUI {
	
	private static final long serialVersionUID = -5357309878561640016L;

	private Config config;
	
	private JLabel title;
	
	private AbstractSyncListPanel fileListPanel;
	
	private AbstractPathPanel syncPanel;
	
	private AbstractPassPanel passPanel;
	
	@Inject
	public MainPanel(@Named("DefaultConfig") Config c)
	{	
		config = c;
		setLayout(new GridBagLayout());
		
		configureTitle();
	}
	
	private void configureTitle()
	{
		title = new JLabel();
		title.setText("Synchroniseren");
		title.setFont(new Font(config.getAsString(Config.KEY_GUI_TITLE_FONT_FAMILY, "Helvetica"), Font.BOLD, config.getAsInt(Config.KEY_GUI_TITLE_FONT_SIZE,24)));
		
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 0;
		c.insets = new Insets(20, 0, 20, 0);
		c.anchor = GridBagConstraints.LINE_START;
		c.fill = GridBagConstraints.HORIZONTAL;
		add(title, c);
	}
	
	
	private void configureSyncPanel()
	{
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 2;
		c.anchor = GridBagConstraints.LINE_START;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.insets = new Insets(20, 0, 0, 0);
		add(syncPanel, c);
	}
	
	private void configurePassPanel() {
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 3;
		c.anchor = GridBagConstraints.LINE_START;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.insets = new Insets(20, 0, 0, 0);
		add(passPanel, c);
	}
	
	private void configureFileList()
	{
		GridBagConstraints c = new GridBagConstraints();
		c.gridx = 0;
		c.gridy = 4;
		c.anchor = GridBagConstraints.LINE_START;
		c.fill = GridBagConstraints.HORIZONTAL;
		c.insets = new Insets(30, 0, 30, 0);
		add(fileListPanel, c);
	}
	
	
	
	@Inject(optional=true)
	public void setAbstractFileListPanel(AbstractSyncListPanel fileListPanel)
	{
		this.fileListPanel = fileListPanel;
		configureFileList();
	}
	
	public AbstractSyncListPanel getAbstractFileListPanel()
	{
		return fileListPanel;
	}
	
	@Inject(optional=true)
	public void setAbstractSyncPanel(AbstractPathPanel fileChooser)
	{
		this.syncPanel = fileChooser;
		configureSyncPanel();
	}
	
	public AbstractPathPanel getAbstractSyncPanel()
	{
		return syncPanel;
	}
	
	@Inject(optional=true)
	public void setAbstractPassPanel(AbstractPassPanel passChanger)
	{
		this.passPanel = passChanger;
		configurePassPanel();
	}
	
	public AbstractPassPanel getAbstractPassPanel()
	{
		return passPanel;
	}
	
}
